/*- Comment
  - Delegate dung de hien thi cac trang theo Category
 */

import QtQuick 2.0
import "../common"
import org.qtproject.znews_qt 1.0

Rectangle {
    id: delegateCategory       // id ten

    width: id_mainwindow.width;
    height: id_mainwindow.height
    property ListModel m_delegateCategoryModel;
    property int m_id; // tham so truyen vao tuong ung voi id - delegateCategory
    property real m_ratio : ApplicationInfo.ratio;
    property int m_heightItem : 140 * m_ratio;
    color: "#cccccc"


    ListView {
        id: id_listArticles
        width: id_mainwindow.width
        height: id_mainwindow.height
        visible: true
        spacing: 8 * m_ratio

        delegate: ArticleDelegate {
            m_cid: m_id
        }

        model : ApplicationInfo.getActicleListModel(m_id)

        PullDownListView {
            id: header
            y: -id_listArticles.contentY - height
        }

        footer: BusyIndicator {
            id: id_footer
            height: m_heightItem * 1.5
        }

        onDragEnded: if (header.refresh) { }

        onMovementEnded: {
            if(id_listArticles.atYBeginning){
                console.log("start beginning Article following Caterory: " + m_id);                
                ApplicationInfo.onUpdateNewArticleRequest(m_id);
            }

            if(id_listArticles.atYEnd){
                console.log("end beginning Article following Category m_id: = " + m_id);                
                ApplicationInfo.onUpdateMoreArticleRequest(m_id);
            }
        }


    }
    ScrollBar {
        scrollArea: id_listArticles;
        height: id_listArticles.height;
        width: 8 * m_ratio
        anchors.right: id_listArticles.right
    }

    // Ham nay se su dung sau
    Component.onCompleted:{
        //id_listArticles.positionViewAtIndex(9, ListView.Beginning)
    }

}
